package com.buchouwang.xiongmaitech.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: xiongmaitech
 * @description: 雄迈 人脸识别摄像头图像识别上传接口
 * @author: ace
 * @Date: 2020-05-22 13:54
 */
@RestController
@Slf4j
public class TestController {

    @PostMapping("/viid/facetemp/report")
    public Map report(@RequestParam("objImg") MultipartFile file, @RequestParam("faceId") String faceId, @RequestParam("temp") float temp, @RequestParam("shotTime") String shotTime) throws IOException {

        if (file.isEmpty()) {
            //TODO  return "上传失败，请选择文件"
        }

        String fileName = file.getOriginalFilename();
        String filePath = "/app/upload/";
        File dest = new File(filePath + fileName);
        try {
            file.transferTo(dest);
            log.info("upload success");
        } catch (IOException e) {
            log.error(e.toString(), e);
        }


        Map returnMap = new HashMap();
        returnMap.put("msg", "成功");
        returnMap.put("state", "ok");

        return returnMap;
    }
}
